<template>
  <div class="app-container">
      <div class="tableClass">
        <el-table :data="formdata" v-loading="loading" :header-cell-style="{background:'#eef1f6',color:'#606266'}"
          border style="width: 100%;">
          <el-table-column align="center" prop="id" label="序号" />
          <el-table-column align="center" prop="order_info.order_num" label="订单号" />
          <el-table-column align="center" prop="thumb_url" label="封面">
            <template slot-scope="scope">
              <el-button type="text" size="medium">
                <img style="width: 50%;" :src="scope.row.thumb_url" />
              </el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="name" label="课程名称" />
          <el-table-column align="center" prop="type_arr" label="课程类型" width="200px">
            <template slot-scope="scope">
              <div v-if="scope.row.type_arr!=''">
                <span v-for="type in scope.row.type_arr" >
                  <el-tag type="warning" style="margin: 5px;">{{type.name}}</el-tag>
                </span>
              </div>
              <div v-else>暂无类型</div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="order_info.pay_amount" label="实付" />
          <!-- <el-table-column align="center" prop="order_info.sex_name" label="支付积分" /> -->
          <el-table-column align="center" prop="order_info.coupon_reduce_price" label="优惠金额" />
          <el-table-column align="center" prop="order_info.type_name" label="订单类型" />
          <el-table-column align="center" prop="order_info.pay_way_name" label="支付方式" />
          <el-table-column align="center" prop="order_info.pay_time" label="支付时间" />
          <el-table-column align="center" prop="cumulative_study_time" label="学习时长">
            <template slot-scope="scope">
                <div>{{scope.row.cumulative_study_time}} 分钟</div>
            </template>
          </el-table-column>
        </el-table>
        <br>
        <!-- 分页 -->
        <div style="text-align: center;">
          <el-pagination background layout="prev, pager, next" @current-change="pageChange" :page-size="pageSize"
            :total="totalusers" />
        </div>
      </div>
    <!-- </el-card> -->
  </div>
</template>

<script>
  export default {
    data() {
      return {
        loading: false,
        keyword: "",
        userId:"",
        formdata: [],
        totalusers: 0, //总行数
        pageSize: 10, //每页几行
        startpage: 1, //起始页
      }
    },
    created() {
       this.userId = this.$route.query.userId;
    },
    mounted() {
      this.getUserBuyCourseList()
    },
    methods: {
      //获取分页列表
      getUserBuyCourseList() {
        let params = {
          "page": this.startpage,
          "limit": this.pageSize,
          "user_id": this.userId
        }
        //调用后台提供的接口方法
        this.$api.getUserBuyCourseList(params).then(res => {
          if (res.data.level == "success") {
            this.formdata = res.data.data
            this.totalusers = res.data.page_info.total
            this.loading = false
          } else {
            this.$message.error(res.data.message)
          }


        })
      },
      //分页 pageChange当前页发生改变触发函数
      async pageChange(page) {
        this.startpage = page
        this.loading = true
        //调用获取列表的方法
        this.getUserBuyCourseList()
      },
    }
  }
</script>
<style scoped="scoped">
  /deep/.el-card__header {
    background-color: #409EFF;
    color: whitesmoke;
  }

  /deep/.el-dialog {
    margin-top: 10vh !important;
    width: 33%;
  }

  .msgDiv {
    width: 80%;
    margin: auto;
    text-align: center;
  }

  .el-input {
    display: flex;
    flex-grow: <2>;
  }
</style>
